<?php

namespace App\Miya\Middlewares;

use Closure;

class SensitiveWord
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (config('setting.open_sensitive_word') == 1) {
            $response = $next($request);
            $content = $response->content();
            $content = str_replace(
                config('miya.filter.words'),
                config('miya.filter.replace'),
                $content
            );
            $response->setContent($content);
            return $response;
        } else {
            return $next($request);
        }
    }
}
